package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlProfiling entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlProfiling
 * @author MyEclipse Persistence Tools
 */

public class MdlProfilingDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlProfilingDAO.class);
	// property constants
	public static final String RUNID = "runid";
	public static final String URL = "url";
	public static final String DATA = "data";
	public static final String TOTALEXECUTIONTIME = "totalexecutiontime";
	public static final String TOTALCPUTIME = "totalcputime";
	public static final String TOTALCALLS = "totalcalls";
	public static final String TOTALMEMORY = "totalmemory";
	public static final String RUNREFERENCE = "runreference";
	public static final String RUNCOMMENT = "runcomment";
	public static final String TIMECREATED = "timecreated";

	public void save(MdlProfiling transientInstance) {
		log.debug("saving MdlProfiling instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlProfiling persistentInstance) {
		log.debug("deleting MdlProfiling instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlProfiling findById(java.lang.Long id) {
		log.debug("getting MdlProfiling instance with id: " + id);
		try {
			MdlProfiling instance = (MdlProfiling) getSession().get(
					"idv.loveloser.dao.MdlProfiling", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlProfiling instance) {
		log.debug("finding MdlProfiling instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlProfiling")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlProfiling instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlProfiling as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByRunid(Object runid) {
		return findByProperty(RUNID, runid);
	}

	public List findByUrl(Object url) {
		return findByProperty(URL, url);
	}

	public List findByData(Object data) {
		return findByProperty(DATA, data);
	}

	public List findByTotalexecutiontime(Object totalexecutiontime) {
		return findByProperty(TOTALEXECUTIONTIME, totalexecutiontime);
	}

	public List findByTotalcputime(Object totalcputime) {
		return findByProperty(TOTALCPUTIME, totalcputime);
	}

	public List findByTotalcalls(Object totalcalls) {
		return findByProperty(TOTALCALLS, totalcalls);
	}

	public List findByTotalmemory(Object totalmemory) {
		return findByProperty(TOTALMEMORY, totalmemory);
	}

	public List findByRunreference(Object runreference) {
		return findByProperty(RUNREFERENCE, runreference);
	}

	public List findByRuncomment(Object runcomment) {
		return findByProperty(RUNCOMMENT, runcomment);
	}

	public List findByTimecreated(Object timecreated) {
		return findByProperty(TIMECREATED, timecreated);
	}

	public List findAll() {
		log.debug("finding all MdlProfiling instances");
		try {
			String queryString = "from MdlProfiling";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlProfiling merge(MdlProfiling detachedInstance) {
		log.debug("merging MdlProfiling instance");
		try {
			MdlProfiling result = (MdlProfiling) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlProfiling instance) {
		log.debug("attaching dirty MdlProfiling instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlProfiling instance) {
		log.debug("attaching clean MdlProfiling instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}